package com.leyou.common.advice;


import com.leyou.common.exception.LyException;
import com.leyou.common.vo.ExceptionResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author:yanjizhw@163.com
 * @date:2019-09-23 11:55
 * 描述: 对符合异常情况的进行捕获，用于全局异常处理
 * @since:1.0.0
 */
@ControllerAdvice
public class CommonExceptionHandler {


    @ExceptionHandler(LyException.class)
    public ResponseEntity<ExceptionResult> handleException(LyException e){

        return ResponseEntity.status(e.getExceptionEnum().getCode())
                .body(new ExceptionResult(e.getExceptionEnum()));
    }
}
